package com.aabte.auth;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Profile(value = {"dev", "test"})
@EnableSwagger2
@Configuration
@EnableKnife4j
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 这里配置swagger扫描的规则，可以是包/类注解/方法注解
                .apis(RequestHandlerSelectors.basePackage(this.getClass().getPackage().getName()))
                // 筛选路径，可是any/正则表达式/antPattern
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Auth APIs")
                .description("Generated by spring-boot-swagger2.")
                .termsOfServiceUrl("")
                .contact(new Contact("Daniel", "", "daniel@aabte.com"))
                .version("v1")
                .build();
    }

}
